package com.longrise.android.byjk.plugins.vip.integralexchange;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.longrise.LEAP.Base.Objects.EntityBean;
import com.longrise.android.byjk.R;
import com.longrise.android.byjk.plugins.tabthird.personal.ChangeSeniorWallDeatilPresenter;
import com.longrise.android.byjk.plugins.tabthird.personal.ChangeSeniorWallDetailContract;
import com.longrise.android.byjk.plugins.tabthird.personal.ChangeWallEvent;
import com.longrise.common.base.BaseActivity2;
import com.longrise.common.utils.AppUtil;

import org.greenrobot.eventbus.EventBus;

/**
 * Created by callxkj on 2017/5/2.
 * 积分兑换点击图片 显示大图和预览界面
 */

public class IntegralExchangeImageActivity extends BaseActivity2<ChangeSeniorWallDeatilPresenter> implements ChangeSeniorWallDetailContract.View,View.OnClickListener {

    public static final String IMAGEURL_INTENT = "imageurl_intent";
    public static final String LOCKSTATE_INTENT = "lockstate_intent"; //解锁状态  1:已解锁  0：未解锁
    public static final String NEEDSCORS_INTENT = "needscors_intent"; //需要的分数
    public static final String DETAILPICURL_INTENT = "detailpicurl_intent"; //预览图片
    public static final String GOODSID_INTENT = "goodsid_intent"; //goodsid
    public static final String GOODSTYPE_INTENT = "goodstype_intent"; //goodtype
    public static final String CURRENT_BACK_POSTION = "current_back_position";

    public static final int PAGE_FROM_PERSONALEX = 1; //来自展业秀更换背景
    public static final int PAGE_FROM_MYINTEGRAL = 2; //来自积分兑换
    public static final String PAGE_FROM_FLAG = "page_from_flag";

//    private ImageView mIv;
    private TextView mBt;
    private String mImageUrl;
    private String mLockState;
//    private TextView mTvright;
//    private RelativeLayout mRlright;
//    private ImageView mIvback;
    private ImageView mIv2;
//    private String mNeedScore;
    private boolean mIsBigPic = true; //当前是不是展示的大图片 或者是预览图片
    private String mDetailpicurl;
    private String mGoodid;
//    private String mGoodtype;
//    private int mFrompage;



    private int mCurrentBackGroundPosition; //当前背景position

    @Override
    public int getContentViewId(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_integralexchangeimage;
    }

    @Override
    public void initView() {
//        mTvright = (TextView) findViewById(R.id.integral_exchange_image_right_tv);
//        mRlright = (RelativeLayout) findViewById(R.id.integral_exchange_image_right_rl);
//        mIvback = (ImageView) findViewById(R.id.integral_exchange_image_backicon);
//        mIv = (ImageView) findViewById(R.id.integral_exchange_image_iv);
        mIv2 = (ImageView) findViewById(R.id.integral_exchange_image_iv2);
        mBt = (TextView) findViewById(R.id.integral_exchange_image_tv);
        setToolbarTitle(AppUtil.getString(R.string.vcard_view));
        getIntentData();
        initEvent();

    }

    @Override
    public void onToolbarBackClick() {
        finish();
    }

    private void initEvent() {
//        mIvback.setOnClickListener(this);
//        mRlright.setOnClickListener(this);
        mBt.setOnClickListener(this);
    }

    private void getIntentData() {
        Intent intent = getIntent();
        mImageUrl = intent.getStringExtra(IMAGEURL_INTENT);
        mLockState = intent.getStringExtra(LOCKSTATE_INTENT);
//        mNeedScore = intent.getStringExtra(NEEDSCORS_INTENT);
        mDetailpicurl = intent.getStringExtra(DETAILPICURL_INTENT);
        mGoodid = intent.getStringExtra(GOODSID_INTENT);
//        mGoodtype = intent.getStringExtra(GOODSTYPE_INTENT);
//        mFrompage = intent.getIntExtra(PAGE_FROM_FLAG, PAGE_FROM_MYINTEGRAL);
        mCurrentBackGroundPosition = intent.getIntExtra(CURRENT_BACK_POSTION, 0);
        initData();
    }

    private void initData() {
//        Glide.with(mContext).load(mImageUrl).into(mIv);
        Glide.with(mContext).load(mDetailpicurl).into(mIv2);
        showBtmBt(mLockState);
//        showRightTvandBg();
    }

    /**
     * 右边显示预览 或者 取消预览
     */
//    private void showRightTvandBg() {
//        if (mIsBigPic) {
//            mTvright.setText("预览");
//            mIv.setVisibility(View.VISIBLE);
//            mIv2.setVisibility(View.GONE);
//        } else {
//            mTvright.setText("取消预览");
//            mIv.setVisibility(View.GONE);
//            mIv2.setVisibility(View.VISIBLE);
//        }
//    }

    /**
     * 底部按钮文字
     *
     * @param lockState //解锁状态  1:已解锁  0：未解锁
     */
    private void showBtmBt(String lockState) {
        switch (lockState) {
            case "1":
                mBt.setText("立即使用");
                mBt.setClickable(true);
                break;
            case "2":
                mBt.setText("使用中");
                mBt.setClickable(false);
                break;
        }
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
//            case R.id.integral_exchange_image_backicon: //返回按钮
//                finish();
//                break;
//
//            case R.id.integral_exchange_image_right_rl: //预览 或者 取消预览
//                mIsBigPic = !mIsBigPic;
////                showRightTvandBg();
//                break;
            case R.id.integral_exchange_image_tv: //底部按钮
                toBtmClick();
                break;
        }
    }

    /**
     * 底部按钮点击
     */
    public void toBtmClick() {
        if ("1".equals(mLockState)) {
            mPresenter.toChangeSkin(mGoodid);
        } else if ("0".equals(mLockState)) {
//            checkIsEnoughIntegral(mGoodid,mGoodtype,mNeedScore);
        }
    }

    @Override
    public void refreshWallData(EntityBean bean) {

    }

    @Override
    public void setRefreshing(boolean isRefresh) {

    }

    @Override
    public void responseChangeSkin() {
        ChangeWallEvent event = new ChangeWallEvent();
        event.setRefresh(true);
        EventBus.getDefault().post(event);
        finish();
    }
}
